Repository navigation
Conversation
golangci-lint copied only the plain sources of the closure, so a package importing Go generated from e.g. protobuf_sources failed typecheck. Hydrate codegen for GoPackageSourcesField and place each generated package at the directory go resolves its import path to. Fixes pantsbuild#23707. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
|
Thanks for the contribution. We've just branched for 2.34.x, so merging this pull request now will come out in 2.35.x, please move the release notes updates to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was written primarily by Claude Code (Claude Opus 5.5). I reviewed the change and its tests before opening it.
Fixes #23707.
Problem
golangci-lintruns the realgotooling over a copy of the module, so every package a linted package imports has to exist as files in the sandbox. The rule copies the plain sources of the transitive closure and never runs codegen. Ago_packagethat imports Go generated from aprotobuf_sourcestarget compiles and tests fine under Pants, butpants lintfailstypecheckwithno required module provides package .... Every other linter on that package then fails with it.Solution
For each target in the closure that the module's import path mapping knows about and that isn't a
go_package, the rule hydrates its sources withenable_codegen=TrueforGoPackageSourcesField. It then writes the generated files wheregolooks for the package: thego.moddirectory joined with the import path relative to the module path.Codegen writes its output beside its own sources (a
.pb.gonext to its.proto), and that is usually not the same directory, so relocating matters. In the new test the proto sits inprotos/withgo_package = "example.com/lint/gen/greeting", and the generated file has to land ingen/greeting/.Nothing in the rule is protobuf-specific. It uses the same
address_to_import_pathmapping that dependency inference uses, so any backend that plugs intoGoModuleImportPathsMappingsHookgets the same treatment.Generated packages whose import path is outside the module path are left out, as before. No directory in the module can provide them, so placing them would need a
replacedirective or ago.work, which is a bigger change.Not included
go vethas the same gap, as the issue notes. It also copies only the linted packages' own sources, not the rest of the closure, and runs from the build root in a single partition. Fixing it properly is a separate change, so I left it out.Testing
test_generated_goinrules_integration_test.pyfails onmainwith thetypecheckerror above and passes with this change. The other golangci-lint tests pass unchanged.🤖 Generated with Claude Code